package com.yuma.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.yuma.tingshu.album.service.BaseCategoryService;
import com.yuma.tingshu.common.result.Result;
import com.yuma.tingshu.model.album.BaseAttribute;
import com.yuma.tingshu.model.album.BaseCategory3;
import com.yuma.tingshu.model.album.BaseCategoryView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"unchecked", "rawtypes"})
public class BaseCategoryApiController {
	
	@Autowired
	private BaseCategoryService baseCategoryService;

	/**
	 * 获取分类列表，包括所有三级分类
	 * 1.返回Result含义
	 * 2.JSONObject
	 * 3.了解相关数据库表设计
	 * 		方案1：三张表：一级分类表，二级分类表，三级分类表，外键关联
	 * 		方案2：一张表：分类表，自关联 id name parent_id
	 * @return
	 */
	@GetMapping("getBaseCategoryList")
	public Result<List<JSONObject>> getBaseCategoryList(){
		List<JSONObject> jsonObjects = baseCategoryService.getBaseCategoryList();
		return Result.ok(jsonObjects);
	}

	/**
	 * 请求路径：/api/album/category/findAttribute/{categoryId}
	 *
	 * 请求参数：占位符参数
	 *
	 * 请求方式：get
	 *
	 * 返回结果集： Result<List<BaseAttribute>>
	 */
	@Operation(summary = "根据一级分类Id 查询分类属性数据")
	@GetMapping("findAttribute/{category1Id}")
	public Result<List<BaseAttribute>> findAttribute(@PathVariable Long category1Id){
		List<BaseAttribute> baseAttributes = baseCategoryService.findAttribute(category1Id);
		return Result.ok(baseAttributes);
	}

	/**
	 * 根据三级分类Id查询视图分类信息
	 * @param category3Id
	 * @return
	 */

	@GetMapping("getBaseCategoryViewByCategory3Id/{category3Id}")
	public Result<BaseCategoryView> getBaseCategoryViewByCategory3Id(@PathVariable Long category3Id){
		BaseCategoryView baseCategoryView = baseCategoryService.getBaseCategoryViewByCategory3Id(category3Id);
		return Result.ok(baseCategoryView);
	}

	/**
	 * 根据一级分类Id查询置顶频道页的三级分类
	 * @param category1Id
	 * @return
	 */
	@GetMapping("findTopBaseCategory3/{category1Id}")
	public Result<List<BaseCategory3>> findTopBaseCategory3(@PathVariable Long category1Id){
		List<BaseCategory3> baseCategory3s = baseCategoryService.findTopBaseCategory3(category1Id);
		return Result.ok(baseCategory3s);
	}

	/**
	 * 根据一级分类Id 获取全部数据
	 * @param category1Id
	 * @return
	 */
	@GetMapping("getBaseCategoryList/{category1Id}")
	public Result<JSONObject> getBaseCategoryList(@PathVariable Long category1Id){
		JSONObject jsonObject = baseCategoryService.getBaseCategoryList(category1Id);
		return Result.ok(jsonObject);
	}

}

